#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 110;
char a[N][N];
int f[N * N];
int n, m;
int dx[] = { 0,1,1,1 };
int dy[] = { 1,-1,0,1 };
int find(int x)
{
    return f[x] == x ? x : f[x] = find(f[x]);
}
void un(int x, int y)
{
    int s = find(x);
    int u = find(y);
    f[u] = s;
}
int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n * m; i++)
        f[i] = i;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (a[i][j] == '.')
            {
                continue;
            }
            else
            {
                for (int k = 0; k < 4; k++)
                {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (y >= 0 && a[x][y] == 'W')
                        un(x * m + y, i * m + j);
                }
            }
        }
    }
    int ret = 0;
    for (int i = 0; i < n * m; i++)
    {
        int x = i / m;
        int y = i % m;
        if (a[x][y] == 'W' && f[i] == i)
        {
            ret++;
        }
    }
    cout << ret << endl;
    return 0;
}